
// 定义类
class Person {
    // 构造方法
    constructor(name = "zhangsan", age = 18) {
        this.name = name;
        this.age = age;
        this.gender = '男';
    }

    say() {
        this.addr = "北京";
        console.log("我是" + this.name + "，今年" + this.age + "岁了！");
    }

    static sayHello() {
        console.log("Hello World!");
    }
}

// 创建对象
let p1 = new Person();
let p2 = new Person("李四", 20, "女");
p1.say();
p2.say();

Person.sayHello();


p1.hobby = "打篮球";

console.log(p1);
console.log(p2);

// 对象字面量
let person = {
    name: "zhangsan",
    age: 18,
    hobby: "打篮球",
    say: function () {
        console.log("我是" + this.name + "，今年" + this.age + "岁了！");
    },
    sayHello: function () {
        console.log("Hello World!");
    }
}

person.say();
console.log(person.name);

// 定义对象, 通过构造函数[不推荐，建议使用class]
function Boy() {
    this.name = "zhangsan";
    this.age = 18;
    this.say = function () {
        console.log("我是" + this.name + "，今年" + this.age + "岁了！", this.gender);
    }
}

let boy = new Boy();


boy.name = "张三";
boy.say();

